package com.dily.study.demo.task;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * Date: 2022-03-14 星期一
 * Time: 16:31
 * Author: Dily_Su
 * Remark: 定时任务
 */
@Component
@ConditionalOnProperty(name = "runSchedule", havingValue = "true")
public class Task {

    Logger logger = LoggerFactory.getLogger(Task.class);

    @Scheduled(cron = "0/10 * * * * ?")
    public void taskTestA() throws InterruptedException {
        logger.info("A:");
        TimeUnit.SECONDS.sleep(5);
    }

    @Scheduled(cron = "0/10 * * * * ?")
    public void taskTestB() {
        logger.info("B:");
    }
}
